<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>热力图</title>

    <link href="http://cdn.bootcss.com/openlayers/4.2.0/ol.css" rel="stylesheet">
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%">
<div id="map" style="width: 100%;height:100%"></div>

<script src="http://cdn.bootcss.com/openlayers/4.2.0/ol.js"></script>
<script type="text/javascript" src="../../dist/iclient9-openlayers.min.js"></script>
<script type="text/javascript">
    var map, url = "http://support.supermap.com.cn:8090/iserver/services/map-china400/rest/maps/China_4326";
    new ol.supermap.MapService(url).getMapInfo(function (serviceResult) {
        var mapJSONObj = serviceResult.result;
        var map = new ol.Map({
            target: 'map',
            controls: ol.control.defaults({attributionOptions: {collapsed: false}})
                .extend([new ol.supermap.control.Logo()]),
            view: new ol.View({
                center: [112, 35],
                zoom: 5,
                projection: 'EPSG:4326'
            })
        });
        var options = ol.source.TileSuperMapRest.optionsFromMapJSON(url, mapJSONObj);
        var layer = new ol.layer.Tile({
            source: new ol.source.TileSuperMapRest(options)
        });
        map.addLayer(layer);
        //创建热力图
        var heatPoints = [];
        var radius = 25;
        var blur = 40;
        var xmax = 130, xmin = 80, ymax = 50, ymin = 20;
        for (var i = 0; i < 100; i++) {
            heatPoints[i] = new ol.Feature(new ol.geom.Point([Math.floor(Math.random() * (xmax - xmin + 1) + xmin), Math.floor(Math.random() * (ymax - ymin + 1) + ymin)]));
        }
        var heatMap = new ol.layer.Heatmap({
            source: new ol.source.Vector({
                features: heatPoints,
                wrapX: false
            }),
            blur: blur,
            radius: radius
        });
        map.addLayer(heatMap);
    });
</script>
</body>
</html>